package com.pic.mgt.syushin.initials;

import com.pic.mgt.initials.InitialBean;
import com.pic.mgt.initials.InitialOperationException;
import com.pic.mgt.log.IgxLog;
import com.pic.mgt.syushin.action.SyushinBusinessApMgtAction;

// (送多方新增)
public class SyushinRedundantApCleanInitialBean implements InitialBean {
	
	private SyushinBusinessApMgtAction syushinBusinessApMgtAction;

	@Override
	public void initialize() throws InitialOperationException {
		// 清除 DB 中多餘的 AP 資料
		boolean isCleanDBSuccess =
			this.syushinBusinessApMgtAction.cleanRedundantApInDB();
		
		// 清除 Syushin Outbox 中 Real 和 Bucket 底下多餘的 AP 目錄
		boolean isCleanFolderSuccess =
			this.syushinBusinessApMgtAction.cleanRedundantApFolder();
		
		if (!isCleanDBSuccess || !isCleanFolderSuccess) {
			throw new InitialOperationException(
					"Initializing failed: Cleaning syushin redundant AP failed.");
		}
		
		// ********************** Log **********************
		if (IgxLog.messageLog.isDebugMode()) {
			IgxLog.messageLog.debug(this,
					"Initializing syushin redundant AP completed.");
		}
		// ********************** Log **********************
	}

	public void setSyushinBusinessApMgtAction(
			SyushinBusinessApMgtAction syushinBusinessApMgtAction) {
		this.syushinBusinessApMgtAction = syushinBusinessApMgtAction;
	}

}
